<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
    <title>Timer - by Vilic JavaScriptQQ交流群56484577</title>
</head>
<body>
    <div id="timer1">
    </div>
    <div id="timer2">
    </div>
    <div id="timer3">
    </div>
</body>

<script type="text/javascript">
   
  
    var addTimer = function () {   
        var list = [],   
            interval;   
  
        return function (id, time) {   
            if (!interval)   
                interval = setInterval(go, 1000);   
            list.push({ ele: document.getElementById(id), time: time });   
        }   
  
        function go() {   
            for (var i = 0; i < list.length; i++) {   
                list[i].ele.innerHTML = getTimerString(list[i].time ? list[i].time -= 1 : 0);   
                if (!list[i].time)   
                    list.splice(i--, 1);   
            }   
        }   
  
        function getTimerString(time) {   
                d = Math.floor(time / 86400),   
                h = Math.floor((time % 86400) / 3600),   
                m = Math.floor(((time % 86400) % 3600) / 60),   
                s = Math.floor(((time % 86400) % 3600) % 60);   
            if (time>0)   
                return d + "天" + h + "小时" + m + "分" + s + "秒";     
            else return "时间到";   
        }   
    } ();   
  
    addTimer("timer1", 99999);   
    addTimer("timer2", 66666);   
    addTimer("timer3", 33333); 
</script>

</html>
